package edu.sdufe.set.treeSet;

import java.util.Comparator;
import java.util.TreeSet;

/**
 * @author wang'ji'cheng
 * @date 2025/6/29
 */
public class Demo2 {
    public static void main(String[] args) {
        TreeSet<Teacher> teacherTreeset = new TreeSet<>(new Comparator<Teacher>() {
            @Override
            public int compare(Teacher o1, Teacher o2) {
                int result = o1.getAge() - o2.getAge();
                result = result == 0 ? o1.getName().compareTo(o2.getName()) : result;
                return result;
            }
        });
        Teacher t1 = new Teacher("张三", 23);
        Teacher t2 = new Teacher("lisi", 24);
        Teacher t3 = new Teacher("wangwu",25);
        Teacher t4 = new Teacher("zhaoliu",23);

        teacherTreeset.add(t1);
        teacherTreeset.add(t2);
        teacherTreeset.add(t3);
        teacherTreeset.add(t4);
        for (Teacher t : teacherTreeset) {
            System.out.println(t);
        }
    }
}
